package guggaTests.utils
{
	import flexunit.framework.TestCase;
	import gugga.utils.DoLaterUtil;
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

	public class DoLaterUtilTest extends TestCase
	{
		private var mTimer : Timer;
		private var mIsMethodExecuted : Boolean;
		
		public function DoLaterUtilTest(methodName:String=null)
		{
			super(methodName);

			mIsMethodExecuted = false;
		}
		
		public function testDoLaterUtil() : void
		{
			setDoLaterMethods();
			
			var timerCompleteHandler : Function = addAsync(assertMehtodWasExecuted, 1100);
			mTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);
		}
		
		private function assertMehtodWasExecuted(aEvent : Event) : void
		{
			assertTrue("TestMethod should be executed", mIsMethodExecuted);
		}
		
		private function setDoLaterMethods() : void
		{
			DoLaterUtil.doLater(method, null, 1, this);
			mTimer = new Timer(1000, 1);
			mTimer.start();
		}
		
		private function method() : void
		{
			mIsMethodExecuted = true;
		}
		
	}
}